import 'package:flutter/widgets.dart';
import 'package:flutter/material.dart' as Curves;

class DialogCenterAnim extends StatefulWidget {
  final Animation<double> animation;
  final Widget child;

  const DialogCenterAnim(
      {Key? key, required this.animation, required this.child})
      : super(key: key);

  @override
  _DialogCenterAnimState createState() => _DialogCenterAnimState();
}

class _DialogCenterAnimState extends State<DialogCenterAnim> {
  late Tween<double> tweenScale;
  late Tween<Offset> tweenOffset;

  late Animation<double> animation;

  @override
  void initState() {
    tweenScale = Tween<double>(begin: 0.6, end: 1.0);
    tweenOffset = Tween<Offset>(begin: const Offset(0, 0), end: const Offset(0, 0));
    animation =
        CurvedAnimation(parent: widget.animation, curve: Curves.standardEasing);
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return AnimatedBuilder(
      animation: widget.animation,
      builder: (BuildContext context, Widget? child) {
        return ScaleTransition(
          scale: tweenScale.animate(animation),
          // alignment: Alignment(0, 0.4),
          child: Transform.translate(
            offset: tweenOffset.evaluate(animation),
            child: FadeTransition(
              opacity: tweenScale.animate(animation),
              child: child,
            ),
          ),
        );
      },
      child: widget.child,
    );
  }
}
